package cn.szq.springframework.beans.factory.support;

import cn.szq.springframework.beans.BeansException;
import cn.szq.springframework.beans.factory.config.BeanDefinition;

/***
 * All rights Reserved, Designed By www.jx-lab.com
 * @Title: AbstractAutowireCapableBeanFactory
 * @Description: 实例化Bean类
 * @author lixy
 * @date 2021/8/12 9:01
 * @version V1.0
 * @Copyright: www.jx-lab.com Inc. All rights reserved.
 * 注意：本内容仅限于众合景轩信息技术有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{

    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;
        try{
            bean = beanDefinition.getBeanClass().newInstance();
        }catch (InstantiationException | IllegalAccessException e){
            throw new BeansException("instantiation of bean failed", e);
        }

        addSingleton(beanName, bean);
        return bean;
    }
}
